# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libdvdnav
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.1.1
pkgrel=2
pkgdesc="The library for xine-dvdnav plugin (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.videolan.org/developers/libdvdnav.html"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-libdvdread")
source=("https://download.videolan.org/pub/videolan/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.bz2"{,.asc}
        https://code.videolan.org/videolan/libdvdnav/-/merge_requests/29.patch
        https://code.videolan.org/videolan/libdvdnav/-/merge_requests/54.patch
        https://code.videolan.org/videolan/libdvdnav/-/merge_requests/56.patch
        001-no-undefined.patch)
sha256sums=('c191a7475947d323ff7680cf92c0fb1be8237701885f37656c64d04e98d18d48'
            'SKIP'
            'e6448f248debd8eb642b2d0f818e04fc4202d4ca51cab4d24dc5b6d630833926'
            '23eedbf73859c0ac919e6777c6503a85b5443f47ed4f4ba6c6bd77e6c993b39f'
            'e759480d05bf3079a2845039f75e1f83f0693dcdf5673c585a7d211fd70523db'
            'c3329ad100f733786c8f263eff499b6dde97b186646db3494a03394c3eb7a0fa')
validpgpkeys=('65F7C6B4206BD057A7EB73787180713BE58D1ADC') # VideoLAN Release Signing Key

_apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  _apply_patch_with_msg \
    29.patch \
    54.patch \
    56.patch \
    001-no-undefined.patch

  autoreconf -fvi
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static
  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
